#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int T, n, m, v, p[N], res, cnt, gone[N], ans, idx;
bool st[N], l;
struct Car{
    int d, v, a;
    double st, fn;
} strm[N];
int main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    scanf("%d", &T);
    while(T--){
        scanf("%d %d %d %d", &n, &m, &l, &v);
        res = 0, cnt = 0, ans = 0, idx = 0;
        for(int i = 0; i < n; i++){
            scanf("%d %d %d", &strm[i].d, &strm[i].v, &strm[i].a);
            if(strm[i].v > v){
                strm[i].st = 1 - strm[i].d;
                if(strm[i].a < 0){
                    strm[i].fn = l - (v * v - strm[i].v * strm[i].v) / (2.0 * strm[i].a) - strm[i].d;
                }else{
                    strm[i].fn = -1.0;
                }
            }else{
                if(strm[i].a <= 0){
                    // printf("%d\n", i);
                    strm[i].st = strm[i].fn = -1.0;
                }else{
                    strm[i].st = l - (v * v - strm[i].v * strm[i].v) / (2.0 * strm[i].a) - strm[i].d;
                    strm[i].fn = -1.0;
                }
            }
            // printf("st: %f, fn: %f\n", strm[i].st, strm[i].fn);
        }
        printf("st: %f, fn: %f\n", strm[1].st, strm[1].fn);
        for(int i = 0; i < m; i++){
            scanf("%d", &p[i]);
            for(int j = 0; j < n; j++){
                if(!st[j] && (l - strm[j].d) >= p[i]){
                    if(j==1){
                        printf("%d\n", p[i]);
                    }
                    if(strm[j].st <= p[i] && strm[j].fn >= p[i]){
                        printf("Cam %d(%d) pass %d(%f, %f)\n", i, p[i], j, strm[j].st, strm[j].fn);
                        // printf("%d %f %f %d\n", j, strm[j].st, strm[j].fn, p[i]);
                        st[j] = true;
                        res++;
                    }
                }
            }
        }
        printf("%d ", res);
        memset(st, 0, sizeof(st));
        for(int i = 0; i < m; i++){
            // printf("Delete %d\n", i);
            cnt = 0;
            for(int j = 0; j < n; j++){
                // printf("Car %d-st:%f, fn:%f, d=%d\n", j, strm[j].st, strm[j].fn, strm[j].d);
                for(int k = 0; k < m; k++){
                    bool f1 = false;
                    for(int e = 0; e < idx; e++){
                        if(k == gone[e]){
                            f1 = true;
                        }
                    }
                    // printf("%d, %d\n", k, p[k]);
                    int tmp = p[k];
                    if(k == i || f1 || (l - strm[j].d) < p[k]){
                        continue;
                    }
                    // printf("    Cam %d, p=%d(%d)\n", k, tmp, p[k]);
                    if(strm[j].st <= p[k] && strm[j].fn >= p[k]){
                        if(!st[j]){
                            cnt++;
                        }
                    }
                    // printf("cnt=%d\n", cnt);
                }
            }
            if(cnt == res){
                ans++;
                gone[idx++] = i;
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}